package com.队列;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * 内置JDK 队列
 */
public class SystemQueue {
    /**
     * toString
     * @param queue
     */
    public void queueString(Queue<Integer> queue){
        StringBuilder builder = new StringBuilder();
        for(int i :queue){
            builder.append(i+"  ");

        }

        System.out.println(String.format("Queue{%s}",builder.toString()));
    }
    public static void main(String[] args) {
        SystemQueue s = new SystemQueue();
        Queue<Integer> queue = new LinkedList<>();


        int  i;
        while (true){
            // System.out.println("出队输入0");
            //System.out.println("结束输入-1");
            System.out.println("输入入队数字：");
            i = new Scanner(System.in).nextInt();
            if(i == -1){
                System.out.println("结束队列");
                break;
            }
            if(i==0){
                if(queue.poll()==null){
                    System.out.println("空队列");
                }
                s.queueString(queue);
            }
            else{
                queue.offer(i);
                s.queueString(queue);

            }

        }

    }
}
